﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.IO;

namespace SantaSLittleIrcHelper
{
    [Serializable()]
    public class Settings
    {
        public String nsEmail, nsConfirmation, nsPassword, nsUsername, ircServer, currentLanguage, defaultLanguage;
        public Boolean verboseMode, debugMode;
        public int ircPort;
        private static Boolean loaded = false;

        public void load()
        {
            loaded = true;
            XmlSerializer x = new XmlSerializer(typeof(Settings));
            FileStream fs = new FileStream("settings.xml", FileMode.Open);
            Settings s = (Settings)x.Deserialize(fs);
            fs.Close();

            this.nsUsername = s.nsUsername;
            this.nsPassword = s.nsPassword;
            this.nsEmail = s.nsEmail;
            this.nsConfirmation = s.nsConfirmation;
            this.ircServer = s.ircServer ?? "irc.traviangames.com";
            this.ircPort = s.ircPort;
            this.verboseMode = s.verboseMode;
            this.defaultLanguage = s.defaultLanguage ?? "en";
            this.currentLanguage = s.currentLanguage ?? "en";
            this.debugMode = s.debugMode;

        }


        public Settings()
        {
            if (!loaded) load();
        }

        public void save()
        {
            XmlSerializer x = new XmlSerializer(typeof(Settings));
            TextWriter writer = new StreamWriter("settings.xml");
            x.Serialize(writer, this);
            writer.Close();
        }

    }


}
